﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Components;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;

namespace GraphicEditor
{
    public partial class Form1 : Form
    {
        private bool loaded = false;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            loaded = true;
            GL.ClearColor(Color.White);
            SetupViewport();
        }

        private void SetupViewport()
        {
            int w = glControl1.Width;
            int h = glControl1.Height;
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Ortho(0, w, 0, h, -1, 1); // Верхний левый угол имеет кооординаты(0, 0)
            GL.Viewport(0, 0, w, h); // Использовать всю поверхность GLControl под рисование
        }

        private void glControl1_Resize(object sender, EventArgs e)
        {
            if (!loaded)
                return;
        }

        private void glControl1_Paint(object sender, PaintEventArgs e)
        {
            if (!loaded)
                return;
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            //glControl1.SwapBuffers();


        }

        private void button1_Click(object sender, EventArgs e)
        {
            Random random = new Random();
            Circle circle = new Circle(random.Next(0, 300), random.Next(0, 300), random.Next(0, 300), Color.Red);
            circle.Paint(5);
            GL.Color3(Color.Blue);
            GL.Begin(BeginMode.Lines);
            GL.Vertex2(1.0f, 1.0f);
            GL.Vertex2(300f, 300f);
            GL.End();
            glControl1.SwapBuffers();
            GL.ClearColor(Color.White);
        }

    }
}
